﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using System.Threading;
using System.Resources;
using System.Globalization;

using MapCenterSystem.DataInfo;
using MapCenterSytem.Process;
using MapCenterSystem.Utility;

namespace MobiMap.Guest
{
    public partial class ServiceDetail : System.Web.UI.Page
    {
        ResourceManager rm;
        CultureInfo ci;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] == null)
                {
                    Response.Redirect("Home.aspx");
                }

                int placeID = int.Parse(Request.QueryString["ID"]);
                PlaceInfo placeInfo = PlaceEx.GetPlaceById(placeID);

                lbName.Text = placeInfo.FullName;
                lbPlaceType.Text = placeInfo.Type.Description;
                lbAddress.Text = placeInfo.Address;
                lbPhone.Text = placeInfo.Phone;
                lbWebsite.Text += placeInfo.Website;
                lbDescription.Text = placeInfo.Info;
                hiddenID.Value = placeID.ToString();

                string imgDirectory = string.Empty;
                if (placeInfo.Picture == string.Empty)
                {
                    placeInfo.Picture = placeInfo.Type.Picture;
                    imgDirectory += "../Icons/PlaceType/";
                }
                else
                    imgDirectory += "../Icons/Place/";

                imgPic.Src = imgDirectory + placeInfo.Picture;
                imgPic.Alt = placeInfo.Picture;

                hiddenFlag.Value = Request.QueryString["flag"];
            }

            //Language
            SetLanguage();
        }

        public void SetLanguage()
        {
            rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));
            HtmlImage imgLanguage = (HtmlImage)Master.FindControl("idLanguage");
            if (Request.Cookies["language"] != null)
            {
                string language = Request.Cookies["language"].Value;
                Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
                LoadString(Thread.CurrentThread.CurrentCulture);

                imgLanguage.Src = "../Image/" + language + ".png";
                return;
            }

            //Defaut language is Vietnamese
            Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");
            ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
            imgLanguage.Src = "../Image/" + "vi-VN" + ".png";
        }

        public void LoadString(CultureInfo ci)
        {
            lbDetailTitile.Text = rm.GetString("ServiceDetail_Title", ci);
            detailDirection.Value = rm.GetString("Info_linkDirection", ci);
            detailNearBy.Value = rm.GetString("Info_linkNearBy", ci);
        }
    }
}
